Skip to content

Conversation

@sagudev
Copy link
Member

@sagudev sagudev commented Nov 11, 2025

Main usages of using global JSContext in servo are from realms, so with this PR we introduce safe realm concepts that are derived from JSContext (this allows us to enforce LIFO of realms). We also introduce counterpart to servos AlreadyInRealm and InRealm: https://github.com/servo/servo/blob/main/components/script_bindings/realms.rs. Eventually these new safe types should replace old servo types. Because this change make it hard to use runtime I removed most methods from it.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever! I'm excited to see how these pieces fit together in Servo!

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This allows us to use realm in place of cx without calling any methods as compiler will deref automatically.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
@sagudev sagudev added this pull request to the merge queue Nov 12, 2025
Merged via the queue into servo:main with commit 8bf5bf8 Nov 12, 2025
68 of 71 checks passed
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Nov 16, 2025
#40582)

Companion to servo/mozjs#650

We added 3 new options to bindings.conf, each more powerful then the
previous one, so one should use the least powerful as possible to keep
things flexible:
1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC
tokens and using functions that do not trigger GC.
2. `cx` prepends argument `&mut JSContext`, which allows everything that
previous one allows, but it also allows calling GC triggering functions.
3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut
to `&mut JSContext` (so it can do everything that previous can), but it
also ensures that there is current entered realm, which can be used for
creation of InRealm.

next steps: #40600 

reviewable per commit

Testing: It's just refactoring
try run: https://github.com/sagudev/servo/actions/runs/19287700927

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Nov 16, 2025
#40582)

Companion to servo/mozjs#650

We added 3 new options to bindings.conf, each more powerful then the
previous one, so one should use the least powerful as possible to keep
things flexible:
1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC
tokens and using functions that do not trigger GC.
2. `cx` prepends argument `&mut JSContext`, which allows everything that
previous one allows, but it also allows calling GC triggering functions.
3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut
to `&mut JSContext` (so it can do everything that previous can), but it
also ensures that there is current entered realm, which can be used for
creation of InRealm.

next steps: #40600 

reviewable per commit

Testing: It's just refactoring
try run: https://github.com/sagudev/servo/actions/runs/19287700927

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants